package com.gxuwz.Market.business.action.web.front;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;

import com.gxuwz.Market.business.entity.ServiceAcademy;
import com.gxuwz.Market.business.entity.ServiceClass;
import com.gxuwz.Market.business.entity.ServiceMajor;
import com.gxuwz.Market.business.entity.ServiceStudio;
import com.gxuwz.Market.business.entity.SysUser;
import com.gxuwz.Market.business.service.IServiceAcademyService;
import com.gxuwz.Market.business.service.IServiceClassService;
import com.gxuwz.Market.business.service.IServiceMajorService;
import com.gxuwz.Market.business.service.IServiceStudioService;
import com.gxuwz.Market.business.service.ServiceAcademyImpl;
import com.gxuwz.Market.business.service.ServiceClassImpl;
import com.gxuwz.Market.business.service.ServiceMajorImpl;
import com.gxuwz.Market.business.service.ServiceStudioImpl;
import com.gxuwz.Market.business.service.SysUserServiceImpl;
import com.gxuwz.core.web.action.BaseAction;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;




public class RegisterAction extends BaseAction implements Preparable, ModelDriven<SysUser>{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected static final String REGISTER_JSP = "/register.jsp";
	protected static final String LOGIN_JSP = "/loginBiHuXueChe.jsp";

	private SysUser sysUser;
	
	private List<ServiceClass> ClassList; //班级
	private List<ServiceMajor> MajorList; //专业
	private List<ServiceAcademy>AcademyList; //学院
	private List<ServiceStudio> StudioList; //科室
	
	@Autowired
	private SysUserServiceImpl sysUserService;
	
	@Autowired
	private IServiceClassService serviceClassService;
	@Autowired 
	private IServiceMajorService serviceMajorService;
	@Autowired
	private IServiceAcademyService serviceAcademyService;
	@Autowired
	private IServiceStudioService serviceStudioService;
	
	

	
	
	/**
	 * 添加注册用户
	 * @return_type: String
	 * @file_name: 
	 * @author: yu
	 * @date: 2018年1月23日
	 * @return
	 */
	public String addRegisteractionUser(){
		
		//将编号转化成名字并赋给用户
		String sAcademy = serviceAcademyService.findByProperty("academyId", sysUser.getUserCollege()).get(0).getAcademyName();
		String sMajor = serviceMajorService.findByProperty("majorId", sysUser.getUserMajor()).get(0).getMajorName();
		String sClass = serviceClassService.findByProperty("classId", sysUser.getUserClass()).get(0).getClassName();
		sysUser.setUserType(0);
		sysUser.setUserCollege(sAcademy);
		sysUser.setUserMajor(sMajor);
		sysUser.setUserClass(sClass);
		
		try {
			sysUserService.add(sysUser);
			setForwardView(LOGIN_JSP);
		} catch (Exception e) {
			System.out.println(e);
		}
	   
		return SUCCESS;
	}
	
	
	/**
	 * 打开注册页面
	 * @return_type: String
	 * @file_name: 
	 * @author: yu
	 * @date: 2018年1月23日
	 * @return
	 */
	
	
//	public String openRegisteractionWeb(){
//		
//		ClassList = serviceClass.findAll();
//		AcademyList =serviceAcademy.findAll();
//		MajorList = serviceMajor.findAll();
//		System.out.println("111111");
//		setForwardView(REGISTER_JSP);
//		return SUCCESS;
//		
//	}
	
	

	@Override
	public SysUser getModel() {
		// TODO Auto-generated method stub
		return sysUser;
	}

	@Override
	public void prepare() throws Exception {
		// TODO Auto-generated method stub
		if(sysUser ==null){
			sysUser =new SysUser();
		}
	}


	public SysUser getSysUser() {
		return sysUser;
	}


	public void setSysUser(SysUser sysUser) {
		this.sysUser = sysUser;
	}


	

	
	public List<ServiceClass> getClassList() {
		return ClassList;
	}


	public void setClassList(List<ServiceClass> classList) {
		ClassList = classList;
	}


	public List<ServiceMajor> getMajorList() {
		return MajorList;
	}


	public void setMajorList(List<ServiceMajor> majorList) {
		MajorList = majorList;
	}


	public List<ServiceAcademy> getAcademyList() {
		return AcademyList;
	}


	public void setAcademyList(List<ServiceAcademy> academyList) {
		AcademyList = academyList;
	}


	public List<ServiceStudio> getStudioList() {
		return StudioList;
	}


	public void setStudioList(List<ServiceStudio> studioList) {
		StudioList = studioList;
	}


	public SysUserServiceImpl getSysUserService() {
		return sysUserService;
	}


	public void setSysUserService(SysUserServiceImpl sysUserService) {
		this.sysUserService = sysUserService;
	}



}
